<?php
namespace App\Helpers;

class ResponseHelper
{
    /**
     * 成功响应
     *
     * @param mixed $data 响应数据
     * @param string $message 提示信息
     * @param int $code 状态码
     * @return \Illuminate\Http\JsonResponse
     */
    public static function success($data = null, $message = '成功', $code = 200)
    {
        return response()->json([
            'status'  => 'success',
            'message' => $message,
            'data'    => $data,
        ], $code);
    }

    /**
     * 失败响应
     *
     * @param string $message 错误信息
     * @param int $code 状态码
     * @param mixed $data 可选的数据
     * @return \Illuminate\Http\JsonResponse
     */
    public static function error($message = '请求失败', $code = 400, $data = null)
    {
        return response()->json([
            'status'  => 'error',
            'message' => $message,
            'data'    => $data,
        ], $code);
    }

    /**
     * 自定义响应
     *
     * @param array $response 自定义响应结构
     * @param int $code 状态码
     * @return \Illuminate\Http\JsonResponse
     */
    public static function custom(array $response, $code = 200)
    {
        return response()->json($response, $code);
    }
}
